const common = require('../../mixins/common')
const pay = require('../../mixins/pay')
import config from "../../utils/config";

const options = {

  /**
   * 页面的初始数据
   */
  data: {
    focus: false,
    topicload: true,
    isCommentPage: false,
    inputValue: '',
    imageValue: '',
    ad: config.videoAd,
    isSingle:true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var scene = decodeURIComponent(options.scene);
    if (scene != 'undefined') {
      this.setData({
        id:scene
      })
      this.postsDetail(scene);
    } else {
      this.setData({
        id:options.id
      })
      this.postsDetail(options.id);
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },
  /**
   * 朋友圈分享
   */
  onShareTimeline(){
    let imageUrl='https://uosat-1316193694.cos.ap-chengdu.myqcloud.com/images/642a913fc3219eadf3cb8872168b858b.png'
    if(this.data.posts[0].images && this.data.posts[0].images.length>=1){
      imageUrl = this.data.posts[0].images[0].img_url
    }else if(this.data.posts[0].video && this.data.posts[0].video.video_thumb_url){
      imageUrl = this.data.posts[0].video.video_thumb_url
    }

    let app = getApp();
     let title = this.data.posts[0].posts_content.slice(0,15);
    return {
      title: title+(title==this.data.posts[0].posts_content?'':'...'),
      path: '/pages/sticky/sticky?id=' + this.data.id,
      imageUrl,
    }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let imageUrl='https://uosat-1316193694.cos.ap-chengdu.myqcloud.com/images/642a913fc3219eadf3cb8872168b858b.png'
    if(this.data.posts[0].images && this.data.posts[0].images.length>=1){
      imageUrl = this.data.posts[0].images[0].img_url
    }else if(this.data.posts[0].video && this.data.posts[0].video.video_thumb_url){
      imageUrl = this.data.posts[0].video.video_thumb_url
    }
    let app = getApp();
    let title = this.data.posts[0].posts_content.slice(0,15);
    return {
      title: title+(title==this.data.posts[0].posts_content?'':'...'),
      path: '/pages/sticky/sticky?id=' + this.data.id,
      imageUrl,
    }
    if (res.from == "button") {
      return {
        title:  "安利一篇好的内容给你，快来..",
        path: '/pages/sticky/sticky?id=' + this.data.postsId,
        imageUrl: 'https://uosat-1316193694.cos.ap-chengdu.myqcloud.com/images/642a913fc3219eadf3cb8872168b858b.png',
      }
    } else {
      return {
        title:  "安利一篇好的内容给你，快来..",
        path: '/pages/sticky/sticky?id=' + this.data.postsId,
        imageUrl: 'https://uosat-1316193694.cos.ap-chengdu.myqcloud.com/images/642a913fc3219eadf3cb8872168b858b.png',
      }
    }
  }
}
pay(options)
common(options)
Page(options)